package com.agileai.bpm.controller.instance;

import java.util.List;

import com.agileai.bpm.bizmoduler.define.WfProcessManage;
import com.agileai.bpm.service.running.ProcessHandle;
import com.agileai.domain.DataParam;
import com.agileai.domain.DataRow;
import com.agileai.hotweb.annotation.PageAction;
import com.agileai.hotweb.controller.core.BaseHandler;
import com.agileai.hotweb.domain.core.User;
import com.agileai.hotweb.renders.LocalRenderer;
import com.agileai.hotweb.renders.ViewRenderer;
import com.agileai.util.StringUtil;

public class WfProcessHistoryListHandler extends BaseHandler{
	public WfProcessHistoryListHandler(){
		super();
	}
	public ViewRenderer prepareDisplay(DataParam param){
		mergeParam(param);
		initParameters(param);
		this.setAttributes(param);
		
		boolean embed = param.getBoolean("embed",false);
		String userId = param.get("userId");
		if (embed){
			User user = (User)this.getUser();
			userId = user.getUserId();
		}
		if (!StringUtil.isNullOrEmpty(userId)){
			List<DataRow> rsList = getService().queryDidWorkList(userId, ProcessHandle.UserSeqType.USER_ID);
			this.setRsList(rsList);
		}
		processPageAttributes(param);
		return new LocalRenderer(getPage());
	}
	
	@PageAction
	public ViewRenderer query(DataParam param){
		return prepareDisplay(param);
	}
	
	protected void processPageAttributes(DataParam param) {
		
	}
	protected void initParameters(DataParam param) {
	
	}
	
	protected WfProcessManage getService() {
		return (WfProcessManage)this.lookupService(WfProcessManage.class);
	}
}	
